package com.ymatou.iapi.thirdpartysync.testcase;

import org.junit.After;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.thirdpartysync.parameter.*;
import com.ymatou.iapi.thirdpartysync.service.*;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.business.service.ProductManagerCallServiceV3;
import com.ymttest.business.service.ThirdpartysyncCallService;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.YMTDateUtil;
/**
*查询推广商品列表Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_QueryPromotionProducts{
	private static QueryPromotionProductsBean querypromotionproductsBean;
	private static QueryPromotionProductsCall querypromotionproductsCall;
	private static int sellerId = Integer.parseInt(EnvSetup.getData("productsellerid"));
	private static String sellerName = EnvSetup.getData("productsellername");
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询推广商品列表Test");
	}

	@Before
	public void caseUp() {
		querypromotionproductsBean=new QueryPromotionProductsBean();
		querypromotionproductsCall=new QueryPromotionProductsCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(querypromotionproductsCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryPromotionProducts_001() {
		Logger.start(true,"正在推广的商品，查询，成功");
		try {
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV3.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject()
					.get("ProductId").getAsString();
			Thread.sleep(3000);
			//添加推广商品
			ThirdpartysyncCallService.insertPromotionProduct(productId, sellerId, 0.03);
			querypromotionproductsBean.setProductId(productId);
			querypromotionproductsBean.setProductName(addProdReq.getProduct().getProductName());
//			querypromotionproductsBean.set
			querypromotionproductsCall.setData(querypromotionproductsBean);
			querypromotionproductsCall.callService();			
			Logger.verifyEquals("200", querypromotionproductsCall.getString("code"), "验证code");
			JsonArray products = querypromotionproductsCall.getJsonObject().getAsJsonObject("data").getAsJsonArray("productList");
			Logger.verifyEquals(1, products.size(), "验证查询size");
			JsonObject pro = products.get(0).getAsJsonObject();
			Logger.verifyEquals(productId, pro.get("productId").getAsString(), "验证productId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryPromotionProducts_002() {
		Logger.start(true,"未进行推广商品查询，查询为空");
		try {
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV3.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject()
					.get("ProductId").getAsString();
			Thread.sleep(3000);
			querypromotionproductsBean.setProductId(productId);
			querypromotionproductsBean.setProductName(addProdReq.getProduct().getProductName());
//			querypromotionproductsBean.set
			querypromotionproductsCall.setData(querypromotionproductsBean);
			querypromotionproductsCall.callService();			
			Logger.verifyEquals("200", querypromotionproductsCall.getString("code"), "验证code");
			Logger.verifyEquals(true, querypromotionproductsCall.getJsonObject().getAsJsonObject("data").get("productList").isJsonNull(), "判断查询为空");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
}